$(document).ajaxSend(function (event, xhr, options) {
    xhr.setRequestHeader("user_token", localStorage.getItem("userToken"));
    console.log("设置user_token成功....");
});

$(document).ajaxError(function (event, xhr, options, exc) {
    if (xhr.status == 401) {
        alert("请先登录！！！")
        location.href = "blog_login.html";
    }
})

function getUserInfo(url) {
    console.log("getUserInfo调用");
    $.ajax({
        type: 'get',
        url: url,
        success: function (result) {
            if (result != null && result.code === "SUCCESS" && result.data != null) {
                $(".container .left .card h3").text(result.data.userName);
                $(".container .left .card a").attr("href", result.data.githubUrl);
            }
        }
    })
}

function logout() {
    localStorage.removeItem("userToken");
    localStorage.removeItem("loginUserId");
    location.href = "blog_login.html";
}